--[[
FilePath: \Lua\View\UIActivityCenter\UIActivityListSignin.lua
周期兑换- 活动签到 
--]]

require 'View/UIBase/UIBase'

UIActivityListSignin = UIBase.New(PanelResNames.UIActivityListSignin)
local _M = UIActivityListSignin

_M.hasInit = false
_M.activeId = nil
_M.dayBtnTab = {}

function _M.Init(func, id)
    _M.activeId = id
    UIBase.Init(_M, func)
end

function _M:OnCreate()
    if not _M.hasInit then
        self:RegisterOnClick(self:GetChild("bgClose"), self.OnBack)
        self.bgImg = self:GetChild("lihui")
        local dayGroup = obj:GetChild("DayGroup")
        self.dayGroupTransition = dayGroup:GetTransition("DayGroup")
        for i = 1, 7 do
            local tempDay = dayGroup:GetChild("Day" .. i);
            table.insert(self.dayBtnTab, tempDay);
        end
        _M.hasInit = true

        self:addEvent()
    end
    self.dayGroupTransition:Play()
    self:Refresh();
    --self.bgImg.url = "ui://UISevenday/" .. SevendayDb[tostring(lastDay)].f_AwardPicture;
end

function _M:addEvent()

end

function _M:removeEvent()
    for i = 1, 7 do
        -- LuaBehaviour:RemoveClick(DayBtnTab[i]);
        self.dayBtnTab[i].onClick:Clear();
    end
end

-- 显示
function _M:OnEnable()
    --if self.activeId == nil or not _M.hasInit then
      --  self:OnBack();
    --else
      --  self.dayGroupTransition:Play()
        --self.tableData, self.serverData = logicMgr.ActiveManager.getActiveData(self.activeId);
        --if self.serverData == nil then
         --   self:OnBack();
          --  return;
        --end
        --self:Refresh();
    --end
end

function _M:Refresh()
    for k, v in pairsByKeys(SevendayDb) do
        local key = tonumber(k);
        local tempBtn = self.dayBtnTab[key];
        tempBtn.onClick:Clear();
        local tempinfo = logicMgr.ActiveManager.sevenDayInfotab[key];
        if (tempinfo ~= nil) then
            tempBtn:GetController("flag").selectedIndex = tempinfo.draw == 1 and 1 or 0;
            tempBtn:GetController("redDot").selectedIndex = tempinfo.draw == 0 and 1 or 0;
        else
            tempBtn:GetController("flag").selectedIndex = 0;
            tempBtn:GetController("redDot").selectedIndex = 0;
        end
        local rewardList = tempBtn:GetChild("list")
        rewardList:RemoveChildrenToPool()
        for i = 1, #itemData do
            local item = rewardList:AddItemFromPool()
            logicMgr.CostManager.RefreshItem(item, itemData[i], {isShowBigNum = true})
        end
        
        tempBtn:GetChild("DayText").text = string.format(getLanguage("Sevenday_1"), k);
    end
end

-- 隐藏
function _M:OnDisable()

end

-- 卸载
function _M:OnDestroy()
    self:removeEvent();
    _M.dayBtnTab = {}
end

return _M;